package top.jlzhou.qqnews;


import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.geccocrawler.gecco.GeccoEngine;
import com.geccocrawler.gecco.pipeline.PipelineFactory;

@Service
public class SpringGeccoEngine {
	
	@Resource
	private PipelineFactory pipelineFactory;
	
	@Value("${qqnews.classPath:top.jlzhou.qqnews.model}")
	private String classPath;
	
	@Value("${qqnews.startPage:http://news.qq.com/articleList/rolls/}")
	private String startPage;
	
	@Value("${qqnews.interval:3000}")
	private int interval;
	
	@Value("${qqnews.loop:true}")
	private boolean loop;

	public PipelineFactory getPipelineFactory() {
		return pipelineFactory;
	}

	public void setPipelineFactory(PipelineFactory pipelineFactory) {
		this.pipelineFactory = pipelineFactory;
	}

	public String getClassPath() {
		return classPath;
	}

	public void setClassPath(String classPath) {
		this.classPath = classPath;
	}

	public String getStartPage() {
		return startPage;
	}

	public void setStartPage(String startPage) {
		this.startPage = startPage;
	}

	public int getInterval() {
		return interval;
	}

	public void setInterval(int interval) {
		this.interval = interval;
	}

	public boolean isLoop() {
		return loop;
	}

	public void setLoop(boolean loop) {
		this.loop = loop;
	}
	
	
	public void start() {
		 GeccoEngine.create()
         .pipelineFactory(pipelineFactory)
         .classpath(classPath)
         .start(startPage)
         .interval(interval)
         .loop(loop)
         .mobile(false)
         .start();
	}

	
}
